package org.aptech.hdax.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.aptech.hdax.pojo.Attendence;
import org.aptech.hdax.pojo.Depatrment;
import org.aptech.hdax.service.AttendenceService;
import org.aptech.hdax.service.DepatrmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
@RequestMapping("/Attendence")
public class AttendenceController {
	
	@Autowired
	private AttendenceService attendenceService;
	@Autowired
	private DepatrmentService depatrmentService;
	
	@RequestMapping(value = "/list",produces = {"application/json;charset=utf-8"})
	@ResponseBody
	public Map<String, Object> list(Attendence attendence,Integer page,Integer limit)throws Exception{
		Map<String, Object>map = new HashMap<String, Object>();
		Page<Attendence>pager=PageHelper.startPage(page,limit);
		map.put("data",attendenceService.getList(attendence));
		map.put("code",0);
		map.put("count",pager.getTotal());
		return map;
	}
	
	@RequestMapping(value = "/listdept",produces = {"application/json;charset=utf-8"})
	@ResponseBody
	public List<Depatrment> listdept()throws Exception{
		return depatrmentService.getAll();
	}
	
	
	
	@PostMapping("/add")
	public String add(Attendence attendence)throws Exception{
		attendenceService.add(attendence);
		return "redirect:/system/index.jsp";
	}
}
